use axum::Router;
use dotenv::dotenv;
use std::env;

pub async fn run(router:Router) {
    dotenv().ok();
    let env_host = env::var("HOST").unwrap_or_default( );
    let env_port = env::var("PORT").unwrap_or_default( );
    let host = if env_host.is_empty() { config::HOST } else { &env_host };
    let port = if env_port.is_empty() { config::PORT } else { &env_port };
    let addr = host.to_owned() + ":" + port;

    let listener = tokio::net::TcpListener::bind( addr ).await.unwrap();
    axum::serve(listener, router.into_make_service()).await.unwrap()
}